//
//  WiringGridViewCell.m
//  GKBHouse
//
//  Created by hcy on 14-1-24.
//
//

#import "WiringGridViewCell.h"

@implementation WiringGridViewCell

- (void)dealloc
{
    self.titleLabel = nil;
    self.checkBtn = nil;
    
    [super dealloc];
}
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)aReuseIdentifier
{
    self = [super initWithFrame:frame reuseIdentifier:aReuseIdentifier];
    if (self) {
        // Initialization code
        
        self.backgroundColor = [UIColor clearColor];
        self.contentView.backgroundColor = self.backgroundColor;
        UIImageView *back = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"sceneCell.png"]];
        [back setFrame:frame];
        self.backgroundView = back;
        [back release];
        
        [self initView];
    }
    
    [self.layer setBorderColor:[UIColor whiteColor].CGColor];
    [self.layer setBorderWidth:2.0f];
    
    return self;
}

- (void)initView
{
    UILabel *titleLabel = [[UILabel alloc]init];
    [titleLabel setBackgroundColor:[UIColor clearColor]];
    [titleLabel setTextColor:[UIColor whiteColor]];
    [titleLabel setText:@"房间A灯1"];
    [self.contentView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    [titleLabel release];
    
    UIButton *checkBtn = [[UIButton alloc]init];
    UIImage *check = [UIImage imageNamed:@"wiringCheckOn.png"];
    UIImage *uncheck = [UIImage imageNamed:@"uncheck.png"];
    [checkBtn setImage:uncheck forState:UIControlStateNormal];
    [checkBtn setImage:check forState:UIControlStateSelected];
    [checkBtn setUserInteractionEnabled:NO];
    [self.contentView addSubview:checkBtn];
    self.checkBtn = checkBtn;
    [checkBtn release];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGRect frame = self.contentView.frame;
    
    CGFloat checkWH = 30.0f;
    CGFloat edgeSpace = 5.0f;
    CGFloat height = frame.size.height;
    
    CGFloat labelWidth = frame.size.width - edgeSpace*2 - checkWH;
    CGRect labelFrame = CGRectMake(edgeSpace, edgeSpace, labelWidth, height - edgeSpace * 2);
    [self.titleLabel setFrame:labelFrame];
    
    CGRect checkFrame = CGRectMake(edgeSpace + labelWidth, edgeSpace, checkWH, height - edgeSpace * 2);
    [self.checkBtn setFrame:checkFrame];
}

@end
